" vim: set foldmethod=marker foldlevel=1: 

" basic setting {{{2
let $LANG = 'en' "set message language
set langmenu=en  "set menu's language of gvim. no spaces besides =
set ignorecase
set smartcase
source $VIMRUNTIME/vimrc_example.vim
"source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
" definition of MyDiff {{{3
function! MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

" MyDiff }}}3

" encoding 
let &termencoding = &encoding
"set termencoding=utf-8
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,cp936

" menu encoding
" source $VIMRUNTIME/delmenu.vim
" source $VIMRUNTIME/menu.vim
" message language
" language messages zh_CN.utf-8
" 

" font
set guifont=Courier_new:h11
set guifontwide=YouYuan:h11  
set cursorline

" toggle menu and toolbar and scrollbar
if has("gui_running")
  set guioptions-=m
  set guioptions-=T
  set guioptions-=r
  set guioptions-=L
  map <silent> <F2> :if &guioptions =~# 'T' <Bar>
          \set guioptions-=T <Bar>
          \set guioptions-=m <bar>
          \set guioptions-=r <bar>
          \set guioptions-=L <bar>
      \else <Bar>
          \set guioptions+=T <Bar>
          \set guioptions+=m <Bar>
          \set guioptions+=r <Bar>
          \set guioptions+=L <Bar>
      \endif<CR>
endif

" disable cursor blink
set gcr=a:blinkon0

" basic setting }}}2

" plugin section {{{1

" before plugin setting {{{2
""" plugin init section
let g:enable_numbers = 0
let g:session_autosave = 'no'

let g:Tlist_Ctags_Cmd = '$VIM/bin/ctags.exe'

let g:windowswap_map_keys = 0 "prevent default bindings
nnoremap <silent> <leader>yw :call WindowSwap#MarkWindowSwap()<CR>
nnoremap <silent> <leader>pw :call WindowSwap#DoWindowSwap()<CR>
"nnoremap <silent> <leader>ww :call WindowSwap#EasyWindowSwap()<CR>

" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" vimwiki
let g:vimwiki_list = [{'path': '$VIM/pkb/', 'path_html': '$VIM/pkb_html/'}]
:nmap <Leader>vv <Plug>VimwikiIndex
:nmap <Leader>vt <Plug>VimwikiTabIndex
:nmap <Leader>vq <Plug>VimwikiUISelect
:nmap <Leader>vi <Plug>VimwikiDiaryIndex
:nmap <Leader>vd <Plug>VimwikiMakeDiaryNote
:nmap <Leader>vt <Plug>VimwikiTabMakeDiaryNote
:nmap <Leader>vy <Plug>VimwikiMakeYesterdayDiaryNote

" notes
let g:notes_directories = [ '$VIM/note' ]

" org
let g:org_indent = 1

" before plugin setting }}}2

" https://github.com/junegunn/vim-plug
call plug#begin('$VIM/vim-plug')

" https://github.com/tpope/vim-repeat
Plug 'tpope/vim-repeat'

" edit assistance plugins {{{2

" https://github.com/jiangmiao/auto-pairs
Plug 'jiangmiao/auto-pairs'

" https://github.com/tpope/vim-surround
Plug 'tpope/vim-surround'

" https://github.com/tpope/vim-unimpaired
Plug 'tpope/vim-unimpaired'

" https://github.com/vim-scripts/VimIM
Plug 'vim-scripts/VimIM'

" https://github.com/junegunn/vim-easy-align
Plug 'junegunn/vim-easy-align'

" https://github.com/easymotion/vim-easymotion
Plug 'easymotion/vim-easymotion'
"Plug 'haya14busa/vim-easyoperator-line'
"Plug 'haya14busa/vim-easyoperator-phrase'
"haya14busa/incsearch.vim
"haya14busa/incsearch-fuzzy.vim
"haya14busa/incsearch-easymotion.vim

" https://github.com/mbbill/undotree
Plug 'mbbill/undotree'

" edit assistance plugins }}}2

" coding assistance plugins {{{2

" https://github.com/scrooloose/nerdcommenter
" Vim plugin for intensely orgasmic commenting
Plug 'scrooloose/nerdcommenter'

" https://github.com/garbas/vim-snipmate
" https://github.com/marcweber/vim-addon-mw-utils
" https://github.com/tomtom/tlib_vim
Plug 'tomtom/tlib_vim'
Plug 'marcweber/vim-addon-mw-utils' 
Plug 'garbas/vim-snipmate'

" https://github.com/SirVer/ultisnips
" TODO compare it with snipmate

" https://github.com/ervandew/supertab
Plug 'ervandew/supertab'

" https://github.com/majutsushi/tagbar
Plug 'majutsushi/tagbar'


" coding assistance plugins }}}2

" syntax plugins {{{2
"" js
" TODO
" https://github.com/pangloss/vim-javascript
Plug 'pangloss/vim-javascript', { 'for': 'js' }
"" Python
" TODO

"" C/C++
" TODO


" syntax plugins }}}2

" navigation plugins {{{2

" https://vim-voom.github.io/
" https://github.com/vim-voom/VOoM
Plug 'vim-voom/VOoM', { 'on': 'Voom' }

" https://github.com/wesQ3/vim-windowswap
Plug 'wesQ3/vim-windowswap'

" http://kien.github.io/ctrlp.vim/
" https://github.com/kien/ctrlp.vim 
Plug 'kien/ctrlp.vim'

" https://github.com/scrooloose/nerdtree
Plug 'scrooloose/nerdtree'

" showing git status on nerdtree
" https://github.com/Xuyuanp/nerdtree-git-plugin
Plug 'Xuyuanp/nerdtree-git-plugin'

" navigation plugins }}}2

" special buffer plugins {{{2

" https://github.com/tpope/vim-fugitive
Plug 'tpope/vim-fugitive'

" https://github.com/itchyny/calendar.vim
Plug 'itchyny/calendar.vim'

" https://github.com/vimwiki/vimwiki
Plug 'vimwiki/vimwiki'

" https://github.com/xolox/vim-notes
Plug 'xolox/vim-notes'

" org mode group {{{3
" https://github.com/jceb/vim-orgmode
Plug 'jceb/vim-orgmode', { 'for': 'org' }

" https://github.com/chrisbra/NrrwRgn
" A Narrow Region Plugin for vim (like Emacs Narrow Region)
Plug 'chrisbra/NrrwRgn'

" https://github.com/inkarkat/vim-SyntaxRange
" Define a different filetype syntax on regions of a buffer
Plug 'inkarkat/vim-SyntaxRange'

" https://github.com/tpope/vim-speeddating
" use CTRL-A/CTRL-X to increment dates, times, and more
Plug 'tpope/vim-speeddating'
" org mode group }}}3

" special buffer plugins }}}2

" colorscheme plugins {{{2

" color scheme
" https://github.com/joshdick/onedark.vim
Plug 'joshdick/onedark.vim'


" colorscheme plugins }}}2

" vim extension {{{2
" https://github.com/xolox/vim-session
" https://github.com/xolox/vim-misc
Plug 'xolox/vim-misc'
Plug 'xolox/vim-session'

" https://github.com/myusuf3/numbers.vim
Plug 'myusuf3/numbers.vim'

" status line
" https://github.com/itchyny/lightline.vim
Plug 'itchyny/lightline.vim'


" vim extension }}}2

" low-layer features {{{2

" https://github.com/vim-scripts/utl.vim
" universal text linking
Plug 'vim-scripts/utl.vim'

" low-layer features }}}2

call plug#end()

" after plugin setting {{{2
set laststatus=2    " status line

syntax on
colorscheme onedark
" after plugin setting }}}2

" plugin section }}}1

" abbreviation section {{{2
" insert date time
iab xdt <c-r>=strftime("=======20%y.%m.%d(%A)=======")<cr>
" abbreviation section }}}2

" key mapping section {{{2
" window
nnoremap <Leader>w <C-w>
nnoremap <Leader>wc :close<CR>
nnoremap <Leader>wo :only<CR>
nnoremap <Leader>ws :split<CR>
nnoremap <Leader>wv :vsplit<CR>
" find
nnoremap <Leader>fc :nohlsearch<CR>

" open files
nnoremap <Leader>rr :e $MYVIMRC<CR>
nnoremap <Leader>gg :e $VIM\gtd\gtd.org<CR>

" undotree
nnoremap <Leader>u :UndotreeToggle<CR>

" toggle nerdtree
map <C-n> :NERDTreeToggle<CR>

" toggle number
nnoremap <Leader>nt :NumbersToggle<CR>
nnoremap <Leader>no :NumbersOnOff<CR>

" toggle full screen
" http://www.vim.org/scripts/script.php?script_id=2596#1.0
map <Leader>FS <Esc>:call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0)<CR>

" maximize
" https://vim.sourceforge.io/scripts/script.php?script_id=1302
map <Leader>MM <Esc>:call libcallnr("maximize.dll", 'Maximize', 1)<CR>
map <Leader>MN <Esc>:call libcallnr("maximize.dll", 'Maximize', 0)<CR>


" key mapping section }}}2


